<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form >
                    <p:panel header="Manage Investigatio Calculations" >
                        <p:panelGrid columns="1" >
                            <p:selectBooleanCheckbox itemLabel="Master Items Only" value="#{investigationController.listMasterItemsOnly}">
                            <p:ajax event="change" process="@this" update="acIx" />
                                </p:selectBooleanCheckbox>
                            <p:panelGrid columns="2" >
                                
                                <h:outputLabel value="Investigation" ></h:outputLabel>
                                <p:autoComplete converter="ixcon" forceSelection="true" id="acIx"  value="#{ixCalController.ix}" completeMethod="#{investigationController.completeInvest}" var="ix" itemLabel="#{ix.name}" itemValue="#{ix}" >
                                    <p:ajax event="itemSelect" process="acIx" update="tbl acIiv" />
                                </p:autoComplete>
                                
                                <h:outputLabel value="Calculation Field" ></h:outputLabel>
                                <p:selectOneMenu id="acIiv" value="#{ixCalController.cal }" >
                                    <f:selectItem itemLabel="Select" />
                                    <f:selectItems value="#{ixCalController.cals}" var="iiv" itemLabel="#{iiv.name}" itemValue="#{iiv}" />
                                    <f:ajax event="change" execute="acIiv" render="tbl" />
                                </p:selectOneMenu>
                            </p:panelGrid>

                            <p:panel>
                                <p:panelGrid columns="2" id="gridDetails" >

                                    <h:outputLabel value="Type" />
                                    <p:selectOneMenu id="cmbCal" value="#{ixCalController.addingIxCal.calculationType}" required="true" requiredMessage="Please select a calculation type" >
                                        <f:selectItems value="#{enumController.calculationTypes}" var="itv" itemLabel="#{itv.label}" itemValue="#{itv}" ></f:selectItems>
                                        <f:ajax event="change" execute="@this" render="gridDetails" ></f:ajax>
                                    </p:selectOneMenu>

                                    <h:panelGroup   id="lblVal">
                                        <h:outputLabel rendered="#{ixCalController.addingIxCal.calculationType eq 'Value'}"   value="Value" />
                                    </h:panelGroup>
                                    <h:panelGroup  id="cmbVal"  >
                                        <p:selectOneMenu rendered="#{ixCalController.addingIxCal.calculationType eq 'Value'}"   value="#{ixCalController.addingIxCal.valIxItem }"  required="true" requiredMessage="Please select a Value" >
                                            <f:selectItem itemLabel="Select Value" />
                                            <f:selectItems value="#{ixCalController.vals}" var="v" itemLabel="#{v.name}" itemValue="#{v}" />
                                        </p:selectOneMenu>
                                    </h:panelGroup>
                                    <h:panelGroup id="lblCon" >
                                        <h:outputLabel  value="Constant"  rendered="#{ixCalController.addingIxCal.calculationType eq 'Constant'}"   />
                                    </h:panelGroup>
                                    <h:panelGroup id="txtCon" >
                                        <p:inputText autocomplete="off"  
                                                     value="#{ixCalController.addingIxCal.constantValue}"  
                                                     required="true" 
                                                     requiredMessage="Please select a constant" 
                                                     rendered="#{ixCalController.addingIxCal.calculationType eq 'Constant'}"/>
                                    </h:panelGroup>


                                    <h:panelGroup id="lblMaleCon" >
                                        <h:outputLabel  value="Constant for Males"  
                                                        rendered="#{ixCalController.addingIxCal.calculationType eq 'GenderDependentConstant'}"   />
                                    </h:panelGroup>
                                    <h:panelGroup id="txtMaleCon" >
                                        <p:inputText autocomplete="off"  
                                                     rendered="#{ixCalController.addingIxCal.calculationType eq 'GenderDependentConstant'}" 
                                                     value="#{ixCalController.addingIxCal.maleConstantValue}"  
                                                     required="true" requiredMessage="Please select a constant for males" />
                                    </h:panelGroup>

                                    <h:panelGroup id="lblFemaleCon" >
                                        <h:outputLabel  value="Constant for Females"  
                                                        rendered="#{ixCalController.addingIxCal.calculationType eq 'GenderDependentConstant'}"    />
                                    </h:panelGroup>
                                    
                                    <h:panelGroup id="txtFemaleCon" >
                                        <p:inputText autocomplete="off"   
                                                     value="#{ixCalController.addingIxCal.femaleConstantValue}"
                                                     required="true" 
                                                     requiredMessage="Please select a constant for females"
                                                     rendered="#{ixCalController.addingIxCal.calculationType eq 'GenderDependentConstant'}" />
                                    </h:panelGroup>


                                    <p:commandButton ajax="false" value="Remove Last" action="#{ixCalController.removeLastCal() }" onclick="onSubmitButton();"  >
                                    </p:commandButton>
                                    <p:commandButton value="Add" action="#{ixCalController.addCal()}" ajax="false" onclick="onSubmitButton();"  >
                                    </p:commandButton>
                                </p:panelGrid>


                            </p:panel>
                            <p:panel >
                                <p:dataTable id="tbl" value="#{ixCalController.items}" var="c" >
                                    <p:column >
                                        <h:outputLabel value="#{c.calculationType}" ></h:outputLabel>
                                    </p:column>
                                    <p:column >
                                        <h:outputLabel value="#{c.constantValue}" rendered="#{c.calculationType eq 'Constant'}"  />
                                        <h:outputLabel  value="#{c.valIxItem.name}"  rendered="#{c.calculationType eq 'Value'}"  />
                                        <h:outputLabel value="Males : #{c.maleConstantValue}, Females : #{c.femaleConstantValue}" rendered="#{c.calculationType eq 'GenderDependentConstant'}"  />
                                    </p:column>

                                </p:dataTable>

                            </p:panel>
                        </p:panelGrid>


                    </p:panel>


                </h:form>


            </ui:define>
        </ui:composition>
    </h:body>
</html>
